﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Muccu
{
    [AttributeUsage(AttributeTargets.Parameter)]
    public class RequiredAttribute : ArgumentValidationAttribute
    {
        public RequiredAttribute()
        {
            this.ErrorMessage = "The argument is required";
        }

        public override bool ServerValidate(object value)
        {
            var val = value as string;
            return !string.IsNullOrEmpty(val);
        }

        public override string ClientValidate
        {
            get
            {
                return @"function(val, messages){ 
    var isValid = (val !=='' && val!==null && typeof val != 'undefined');
    if(!isValid)messages.push(""" + ErrorMessage + "\"); return isValid;}";
            }
        }
    }
}
